<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<script src="/soundmanagerv/script/soundmanager2.js"></script>
<script>
var smSucc,smError,smDidi;    
soundManager.setup({
  url: '/soundmanagerv/swf',
  flashVersion: 9, // optional: shiny features (default = 8)
  // optional: ignore Flash where possible, use 100% HTML5 mode
  // preferFlash: false,
});

function playSound(name){
   soundManager.createSound({
        url: '/images/storage/'+name+'.mp3?rnd='+ Math.random() ,
        autoLoad: true,
        autoPlay: true,
        volume: 50
    });
}

 $(document).ready(function(){ 
    $('#locationNo').focus().keyup(function(e){
        if(e.keyCode === 13){
            playSound('go');
            $('#code').show();
            $('#bang').show();
            $('#barcode').focus();
            $('#restext').css('background-color','yellow');
            $('#restext').html("请输入条形码……");
            $('#restext').show();            
        }
    });
    $('#code').hide();
    $('#bang').hide();
    var focusInput =0;
    $('#barcode,#locationNo').focus(function(){            
        var This=this;
        setTimeout(function(){focusInput = $(This).attr('id');checkfocus();},100);            
    }).blur(function(){
        focusInput =0;
        setTimeout(function(){checkfocus();},150);
    });
    function checkfocus(){
        if(focusInput !== 'locationNo' && focusInput !== 'barcode'){
            $('#barcode').focus();
        }
    };
    $('#barcode').keyup(function(e){          
    var locationNo = $('#locationNo').val();
    var barcode = $('#barcode').val();        
    $('#restext').show();
    if(e.keyCode === 13){           
       if(barcode.length === 5){
            playSound('go');
            $('#locationNo').val(barcode);
            $('#barcode').val("");
            $('#barcode').focus();
            $('#restext').css('background-color','yellow');
            $('#restext').html("请输入条形码……");
       }else{
        $('#restext').css('background-color','yellow');
        $('#restext').html("正在获取数据……");   
        $.post(
            '/admini/managestore/instorage',
            {'locationNo':locationNo,'barcode':barcode},
            function(data){
                if(data.type === 1){
                    playSound('success');
                    $('#restext').css('background-color','#05BC62');
                    $('#restext').html("该库位号与该包裹("+data.sno+":"+data.nikename+")对应<br/>该用户占用的仓库位: ");
                    $.each(data.storeNo , function(index,content){
                        $('#restext').html($('#restext').html()+'| '+content+";");
                    });
                    $('#locationNo').val(locationNo);
                    $('#barcode').val("");
                    $('#barcode').focus();
                }else if(data.type === 6){
                    //$('#success')[0].play();
                    playSound('success');
                    $('#locationNo').val(locationNo);
                    $('#barcode').val("");
                    $('#barcode').focus();
                    $('#restext').css('background-color','#05BC62');
                    $('#restext').html("该库位号为空,该用户("+data.sno+":"+data.nikename+")成功占领该库位<br/>该用户占用的仓库位：");
                    $.each(data.storeNo , function(index,content){
                        $('#restext').html($('#restext').html()+'| '+content+";");
                    });                        
                }else if(data.type === 7){
                    //$('#error')[0].play();
                    playSound('xuxushishi');
                    $('#locationNo').val(locationNo);
                    $('#barcode').val("");
                    $('#barcode').focus();
                    $('#restext').css('background-color','red');
                    $('#restext').html("该库位号为空,但绑定失败");                       
                }else if(data.type === 2){
                    playSound('success');
                    $('#restext').css('background-color','#05BC62');
                    $('#restext').html("该用户("+data.sno+":"+data.nikename+")绑定该库位<br/>该用户占用的仓库位：");
                    $.each(data.storeNo , function(index,content){
                        $('#restext').html($('#restext').html()+'| '+content+";");
                    });
                    $('#locationNo').val(locationNo);
                    $('#barcode').val("");
                    $('#barcode').focus();                        
                }else if(data.type === 3){
                    playSound('xuxushishi');
                    $('#restext').css('background-color','red');
                    $('#restext').html('包裹不存在……');
                    $('#barcode').val("");
                    $('#barcode').focus();                        
                }else if(data.type === 4){
                    playSound('xuxushishi');
                    $('#restext').css('background-color','red');
                    $('#restext').html('该库位不存在……');
                    $('#barcode').val("");
                    $('#barcode').focus();                        
                }else if(data.type === 5){
                    playSound('xuxushishi');
                    $('#restext').css('background-color','red');
                    $('#restext').html('该库位已经被别的用户('+data.sno+":"+data.nikename+')占用……<br/>该包裹对应的库位号为:');
                    $.each(data.storeNo , function(index,content){
                        $('#restext').html($('#restext').html()+'| '+content+";");
                    });
                    $('#barcode').val("");
                    $('#barcode').focus();                        
                }else if(data.type === 8){
                    playSound('success');
                    $('#restext').css('background-color','#05BC62');
                    $('#restext').html("该库位号与该包裹("+data.sno+":"+data.nikename+")对应<br/>该包裹已出库<br/>该用户占用的仓库位: ");        //该包裹与该用户相对应(已经出库的包裹重新扫描)
                    $.each(data.storeNo , function(index,content){
                        $('#restext').html($('#restext').html()+'| '+content+";");
                    });
                    $('#locationNo').val(locationNo);
                    $('#barcode').val("");
                    $('#barcode').focus();
                }else if(data.type === 9){
                    playSound('success');
                    $('#restext').css('background-color','#05BC62');
                    $('#restext').html("该用户("+data.sno+":"+data.nikename+")绑定该库位<br/>该包裹已出库<br/>该用户占用的仓库位：");        //该用户绑定该库位(已经出库的包裹重新扫描)
                    $.each(data.storeNo , function(index,content){
                        $('#restext').html($('#restext').html()+'| '+content+";");
                    });
                    $('#locationNo').val(locationNo);
                    $('#barcode').val("");
                    $('#barcode').focus();
                }else if(data.type === 10){
                    playSound('success');
                    $('#restext').css('background-color','#05BC62');
                    $('#restext').html("该库位号为空,该用户("+data.sno+":"+data.nikename+")成功占领该库位<br/>该包裹已出库<br/>该用户占用的仓库位：");        //该库位号是空的,并且该用户成功绑定该库位(已经出库的包裹重新扫描)
                    $.each(data.storeNo , function(index,content){
                        $('#restext').html($('#restext').html()+'| '+content+";");
                    });
                    $('#locationNo').val(locationNo);
                    $('#barcode').val("");
                    $('#barcode').focus();
                }else if(data.type === 11){
                    playSound('success');
                    $('#restext').css('background-color','#05BC62');
                    $('#restext').html("该包裹("+barcode+")存放在特殊库位 "+locationNo);
                    $('#locationNo').val(locationNo);
                    $('#barcode').val("");
                    $('#barcode').focus();                    
                }
            },
            'json');
        }
    }
   });       
});


</script>
</head>
<body>
<div data-role="page" id="page1">
    <div data-theme="a" data-role="header">
        <a data-role="button" href="javascript:goback();" class="ui-btn-left">
            返回
        </a>
        <h3>
            悠奇-商品扫描入库
        </h3>
    </div>
    <div data-role="content">
            <div data-role="fieldcontain">
                <label for="locationNo">
                    请扫描仓库号
                </label>
                <input name="locationNo" id="locationNo" placeholder="请扫描仓库号" value="" type="text">
            </div>
            <div data-role="fieldcontain" id="code">
                <label for="barcode">
                    请扫描商品条码
                </label>
                <input name="barcode" id="barcode" placeholder="请扫描商品条码" value="" type="text">
            </div>
            <div id="restext" style="padding:10px 40px;">
                
            </div>
            <!--<div class="ui-grid-a" id="bang">
                <div class="ui-block-a">
                    <input type="button" data-theme="e" value="扫描入库">
                </div>
                <div class="ui-block-b">
                    <a data-role="button" id="play" href="#page1">
                        清空
                    </a>
                </div>
            </div>-->
    </div>
</div>
<script type="text/javascript">
function goback(){
    window.location.href="/admini/managelogin/tabletlist";
}
</script>
</body>
</html>